<template>
   
  <div>
    <el-dialog
      :title="form.id ? '管理员编辑' : '管理员添加'"
      :visible.sync="oppen.off"
    >
      {{ form }}
      <el-form :model="form">
        <el-form-item label="管理员角色" :label-width="formLabelWidth">
          <el-select v-model="form.roleid" placeholder="请选择">
         
            <el-option
              v-for="(item, index) in meuns"
              :key="index"
              :label="item.rolename"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="管理员名称" :label-width="formLabelWidth">
          <el-input v-model="form.username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="管理员密码" :label-width="formLabelWidth">
          <el-input v-model="form.password" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="管理员状态">
          <el-switch
            v-model="form.status"
            active-color="#13ce66"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="2"
          >
          </el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="oppen.off = false">取 消</el-button>
        <el-button type="primary" @click="submit()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ["list", "oppen","meuns"],
  data() {
    return {
      dialogFormVisible: false,
      form: {
        roleid: 1,
        username: "",
        password: "",
        status: 1,
        uid: "",
      },
      formLabelWidth: "120px",
    };
  },
  methods: {
    submit() {
      if (this.form.uid === "") {
        this.$api.managerAdd(this.form).then((res) => {
          console.log(res);
          this.$message({
            message: "管理员信息添加成功",
            type: "success",
          });
          this.form = {
            roleid: 1,
            username: "",
            password: "",
            status: 1,
            uid: "",
          };
          this.oppen.off = false;
          //   this.$router.go(0);
        });
      } else {
        this.$api.managerEdit(this.form).then((res) => {
          // console.log(res);
          this.$message({
            message: "管理员信息修改成功",
            type: "success",
          });
          this.form = {
            roleid: 1,
            username: "",
            password: "",
            status: 1,
            uid: "",
          };
          this.oppen.off = false;
        });
      }
      this.$router.go(0);
    },
  },
  created() {},
  mounted() {},
  components: {},
  computed: {},
  watch: {},
};
</script>

<style lang='scss' scoped>
</style>
